# -*- coding: GBK -*-
import psutil
import json

def get_network_info():
    net_info = []
    addrs = psutil.net_if_addrs()
    stats = psutil.net_if_stats()
    for interface in addrs:
        interface_info = {
            "interface": interface,
            "is_up": stats[interface].isup,
            "speed": f"{stats[interface].speed} Mbps",
            "addresses": addrs[interface][1].address
        }
        net_info.append(interface_info)
    print(json.dumps(net_info, ensure_ascii=False, indent=2))

get_network_info()
